Environment variables in NET By Rob Janssen, PE1CHL. NET has been enhanced with support for variables. This means you can set variables to some (string) value, and use these values in commands. This is especially useful in the configuration files. Also, some variable names are reserved to hold the names of the different directories and files referenced by NET, so that you can now locate these wherever you like. setenv command Variables are set using the "setenv" command in NET. The possible uses are: setenv setenv without parameters displays the currently defined variables, in alphabetic order, with their values. setenv name value the variable "name" is given "value" as it's value. the previous value of "name" is lost, and the variable is created automatically if it did not yet exist. setenv name the variable "name" loses it's value and will not be displayed by "setenv" any more. this is different from assigning an empty value to the variable, which can be done using: setenv name "". setenv name=value this form is allowed as an alternative to the second case. The name of a variable can contain letters, digits and the underscore character, and it is always converted to UPPER CASE before it is stored or referenced. After a variable has been assigned using setenv (or other means, see below), it can be used in 2 basically different ways: 1. Implicitly used by NET When the name of the variable is one of the reserved names, NET will automatically use it. It is generally unwise to set these reserved variables to empty or nonsense values, as this may cause problems in the operation of NET. The reserved names are: NETSTART Initialization file NETUSERS Authorized FTP users and passwords NETHOSTS Network host table NETFINGER Finger file path NETMAILS Incoming mail NETMAILQ Outgoing mail spool NETROUTEQ Queue for router NETALIAS The alias file And, on the Atari ST: TMPDIR Temp files directory So, by using the command "setenv NETHOSTS d:\hosts.net", you change the name of the hosts file to "d:\hosts.net", and if this is on a RAM-disk the lookup of hostnames will be somewhat faster. 2. Explicit use in a NET command A variable can be used in every NET command instead of (parts of) a command name or a parameter. Variables are referenced using the $ sign followed by their name, as in: attach netrom $CALLSIGN In this case, $CALLSIGN is replaced by the contents of the variable CALLSIGN before the command is executed. A variable can also contain part of a parameter, as in: attach asy 3f8 4 ax25 ax0 512 256 4800 $CALLSIGN-2 In this case, the -2 ssid will be appended to the callsign stored in the variable CALLSIGN. When the text to be appended could be mistaken for part of the variable name, the name can be enclosed in braces: ${VARNAME}000. There also exist some more advanced ways of referencing variables, to make it possible to provide defaults for undefined ones: ${NAME-default} This will return the value of the variable NAME if it is defined, or "default" if NAME is undefined. ${NAME=default} Acts the same as the privious case, but it additionally sets the variable NAME to value "default" if it did not exist. ${NAME?text} When NAME is defined, returns it's value. If not, it prints "text" and the commandline is not executed. When "text" is not present, "undefined variable" is printed. ${NAME+text} When NAME is defined, returns "text". When NAME is not defined, returns an empty string. Initial setting of variables The value of variables at the time NET is started is determined as follows: 1. When NET is started, the variable table is empty. It first inserts de default values of the "reserved" variables into the table. The values are the pathnames that used to be fixed in earlier releases, e.g.: NETMAILQ=/spool/mqueue/ 2. The variables in the environment passed by the operating system are added to the table, possibly replacing the defaults. This means a variable can be given an initial value by putting it in the environment of the shell that starts NET (in MS-DOS: using a SET command in COMMAND.COM) 3. Parameters to the NET program of the form "name=value" are parsed as "setenv" commands. This continues from left to right until a parameter is encountered that does not contain an "=" sign, or all parameters have been parsed. 4. NET performs internal initializations, that possibly use the variables defined up to this moment. Thereafter it prints the banner. 5. When there are no more parameters, the file whose name is in the variable NETSTART is executed as a command file. Normally this will be AUTOEXEC.NET. If there are parameters left at this point, they are examined from left to right. If they don't contain an "=" sign they are assumed to be filenames and executed as a command file, if they do contain an "=" they are parsed as "setenv" commands. 6. The prompt is printed and NET starts operating interactively. Example of a NET commandlines: net callsign=pe1chl autoexec.st2 running=1 This starts NET with variable CALLSIGN set to value "pe1chl", then NET reads the startupfile "autoexec.st2" and after this file has been completely executed, variable RUNNING is set to 1. net callsign=pe1chl Same as above, but the default startup file defined in NETSTART is executed with variable CALLSIGN set to "pe1chl". Note that in this case it is still possible to run a nonstandard startupfile if you define it's name in the environment of the shell. For MS-DOS this can be done by typing set netstart=autoexec.2 from the COMMAND.COM prompt. Environment passed to sub-shells When NET starts a sub-shell (using the command "shell" or "!"), it passes the values of all variables as an environment to this sub-shell. As it reads in the environment itself during startup, this passed environment at least contains the required variables for every executed shell. But as it also contains the variables that you can set yourself, this feature can be used to define the environment for a mailer run from NET, using setenv commands in the startup file.